package com.hb.znpt.viewmodel;

import android.app.Application;
import android.os.Handler;

import androidx.annotation.NonNull;

import com.hb.znpt.activity.LoginActivity;
import com.hb.znpt.activity.MainActivity;
import com.hb.znpt.model.SplashModel;
import com.hb.znpt.utils.Constants;
import com.unitlib.base.base.BaseViewModel;
import com.unitlib.base.utils.SPUtils;

public class SplashViewModel extends BaseViewModel<SplashModel> {

    public SplashViewModel(@NonNull Application application) {
        super(application);
    }

    @Override
    public void onCreate() {
        if (SPUtils.getInstance().getBoolean(Constants.SP_LOGINSTATUS, false)) {
            startActivity(MainActivity.class);
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    activity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            finish();
                        }
                    });
                }
            }, 1 * 1000);

        } else {
            startActivity(LoginActivity.class);
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    activity.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            finish();
                        }
                    });
                }
            }, 1 * 1000);
        }
    }
}
